package preprocess;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import trouger.dmt.JoinTableRunner;
import trouger.dmt.JoinType;
import utils.Utils;

public class SelectPvSearchClickByBuyerSamples implements Tool{
	public static String getSelectPvSearchClickByBuyerSamplesedPath(String date) {
		return Utils.rootDir + date + "/PvSearchClickBySamples/";
	}
	@Override 
	public Configuration getConf() {
		return null;
	}
	
	@Override
	public void setConf(Configuration conf) {
		
	}
	/*
	 * 
	 * 1.search[1~25]
	 * 26.UUID
	 * 27.pv时间
	 * 28.直达后类目
	 * 29.商品idlist
	 * 30.clicklist[点击时间^A搜索的来源pid^A点击位置^A点击商品id(数字)^A是否为豆腐块商品^B....]
	 */
	@Override
	public int run(String[] args) throws Exception {
		String pvSearchClickFile = PvSearchClickJoiner.getPvSearchClickDetailPath(args[0]);
		String output = getSelectPvSearchClickByBuyerSamplesedPath(args[0]);
		String buyerSamples = SelectBuyer.getSelectedBuyerPath(args[0]);
		System.out.println("start job SamplePvSearchClick...");
		System.out.println("pvSearchClickFile: " + pvSearchClickFile);
		System.out.println("buyerSamples: " + buyerSamples);
		System.out.println("output: " + output);
		if (Utils.exitSystem(args))
			return -1;
		JoinTableRunner r = new JoinTableRunner();
		r.addSourceTable(pvSearchClickFile, "UTF-8", "\t");
		r.addSourceTable(buyerSamples, "UTF-8", "\t");
		r.addKeyGroup("1.4, 2.1");	
		r.setJoinType(JoinType.InnerJoin);
		StringBuilder columns = new StringBuilder();
		for (int i = 1; i < 30; ++i)
			columns.append("1." + String.valueOf(i) + ", ");
		columns.append("1.30");
		r.setResultFieldsEx(columns.toString());
		r.setResultTable(output);
		r.run("SamplePvSearchClick");
		return 0;		 	
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		Utils.checkArgs(args);
		
		// TODO Auto-generated method stub
		int res = ToolRunner.run(new SelectPvSearchClickByBuyerSamples(), args);
		System.exit(res);
	}
}
